/**
 * 返回图表需要的数据
 * */

/* 返回 图表数据 混合类型 */
const getData1 = (data, opt) => {
  let series = opt.series;
  opt.title.text = data.title;

  series.forEach((item) => {
    item.data = [];

    let currentModel = eval('data.' + item.seriesKey);
    let months = ['m01', 'm02', 'm03', 'm04', 'm05', 'm06', 'm07', 'm08', 'm09', 'm10', 'm11', 'm12'];

    for (let i = 0; i < months.length; i++) {
      let key = months[i];
      let val = parseFloat(currentModel[key]);
      item.data.push(val);
    }
  });

  return opt;
}

/* 返回 贡献度 柱状图 */
const getData2 = (data, opt) => {
  opt.title.text = data.title;

  opt.xAxis.data = eval('data.' + opt.xAxis.seriesKey);           // 横坐标
  opt.series[0].data = eval('data.' + opt.series[0].seriesKey);   // 组装图表数据

  return opt;
}

/* 返回 贡献度 柱状瀑布 */
const getData2_2 = (data, opt) => {
  opt.xAxis.data = data.value.series1Title;

  opt.series[0].data = data.value.series1;
  opt.series[1].data = data.value.series2;
  opt.series[2].data = data.value.series3;

  return opt;
}

/* 返回 园区占比 玫瑰图 */
const getData3 = (data, opt) => {
  opt.title.text = data.title;
  opt.series[0].data = [];
  let value = data.value;

  for (let i = 0; i < value.series1.length; i++) {
    opt.series[0].data.push({
      name: value.series1Title[i],
      value: value.series1[i]
    });
  }

  opt.series[0].data.sort((a, b) => { return a.value - b.value; });   // 排序
  return opt;
};

/* 返回 业态占比 饼图 */
const getData4 = (data, opt) => {
  opt.title.text = data.title;

  opt.series[0].data[0].value = data.value.series1[0];    // 独立
  opt.series[0].data[1].value = data.value.series1[1];    // 护理
  opt.series[0].data[2].value = data.value.series1[2];    // 医院

  return opt;
};


/* 返回表格数据 */
const tabDataSource = () => {
  return [
    { name: '今年预算(万元)', seriesKey: 'value.series1' },
    { name: '今年实际(万元)', seriesKey: 'value.series2' },
    { name: '去年实际(万元)', seriesKey: 'value.series3' },
    { name: '达成率(%)', seriesKey: 'contrasts.series1' },
    { name: '同比(%)', seriesKey: 'contrasts.series2' },
  ]
}

/* 返回表格数据 销售 */
const tabDataSource2 = () => {
  return [
    { name: '退住(万元)', seriesKey: 'value.series1' },
    { name: '新增入住(万元)', seriesKey: 'value.series2' },
    { name: '净新增预算(%)', seriesKey: 'contrasts.series1' },
  ]
}

/* 销售 医院床位使用率 */
const tabDataSource3 = () => {
  return [
    { name: '今年预算(万元)', seriesKey: 'value.series1' },
    { name: '今年实际(万元)', seriesKey: 'value.series2' },
    { name: '达成率(%)', seriesKey: 'contrasts.series1' },
  ]
}



export { getData1, getData2, getData2_2, getData3, getData4, tabDataSource, tabDataSource2, tabDataSource3 };
